package com.friendfeed.api;

import org.json.JSONException;
import org.json.JSONObject;

public class MediaContent {
    private String url;
    private String type;
    private int width;
    private int height;

    public MediaContent(String url, String type, int width, int height) {
        this.url = url;
        this.type = type;
        this.width = width;
        this.height = height;
    }

    public MediaContent(JSONObject jsonObject) throws JSONException {
        if (jsonObject.has("url") && !jsonObject.isNull("url")) {
            url = jsonObject.getString("url");
        }
        if (jsonObject.has("type") && !jsonObject.isNull("type")) {
            type = jsonObject.getString("type");
        }
        if (jsonObject.has("width") && !jsonObject.isNull("width")) {
            width = jsonObject.getInt("width");
        }
        if (jsonObject.has("height") && !jsonObject.isNull("height")) {
            height = jsonObject.getInt("height");
        }
    }

    public String getUrl() {
        return url;
    }

    public String getType() {
        return type;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public String toString() {
        return "MediaContent{" +
                "height=" + height +
                ", width=" + width +
                ", type='" + type + '\'' +
                ", url='" + url + '\'' +
                '}';
    }
}
